q = str(input())
a = []
s = []
d = []
for i in q:
    a.append(i)
if len(a) == 4 and q != int(q):
    q1 = int(a[0] + a[1] + a[2] + a[3])
    q2 = int(a[0] + a[1] + a[2])
    q3 = int(a[1] + a[2] + a[3])
    q4 = int(a[0] + a[1])
    q5 = int(a[1] + a[2])
    q6 = int(a[2] + a[3])
    q7 = int(a[0])
    q8 = int(a[1])
    q9 = int(a[2])
    q10 = int(a[3])
    s.append(q1)
    s.append(q2)
    s.append(q3)
    s.append(q4)
    s.append(q5)
    s.append(q6)
    s.append(q7)
    s.append(q8)
    s.append(q9)
    s.append(q10)
    for i in s:
        p = 0
        for j in range(2, int(i)):
            if int(i) % j == 0:
                p = 1
                break
        if p == 0:
            d.append(i)
    if len(d) == 0:
        print('0')
    else:
        print(max(d))
else:
    print('0')
